package com.mtk.launcher.util.shared;


import android.text.TextUtils;

import com.google.gson.Gson;
import com.mtk.launcher.MyApplicaiton;
import com.mtk.launcher.power.bean.TimeDealEntity;

public class SharedPerManager {

    public static TimeDealEntity getPowerOnOffTime() {
        if (!getPowerOnOffEnable()) {
            //如果未打开的话，直接返回null,外边逻辑只用这一个判断
            return null;
        }
        if (timeDealEntityCache != null) {
            return timeDealEntityCache;
        }
        String json = (String) MyApplicaiton.getInstance().getData("TimeDealEntity", "");
        if (TextUtils.isEmpty(json)) {
            return null;
        }
        initGson();
        timeDealEntityCache = gson.fromJson(json, TimeDealEntity.class);
        return timeDealEntityCache;
    }

    private static Gson gson;

    private static void initGson() {
        if (gson == null) {
            gson = new Gson();
        }
    }

    private static TimeDealEntity timeDealEntityCache = null;

    public static void setPowerOnOffTime(TimeDealEntity timeDealEntity, String printTag) {
        timeDealEntityCache = timeDealEntity;
        String json = "";
        if (timeDealEntity != null) {
            initGson();
            json = gson.toJson(timeDealEntity);
        }
        MyApplicaiton.getInstance().saveData("TimeDealEntity", json);
    }


    private static int screenWidthCache = -1;

    public static int getScreenWidth() {
        if (screenWidthCache != -1) {
            return screenWidthCache;
        }
        screenWidthCache = (int) MyApplicaiton.getInstance().getData("ScreenWidth", 1920);
        return screenWidthCache;
    }

    public static void setScreenWidth(int ScreenWidth) {
        screenWidthCache = ScreenWidth;
        MyApplicaiton.getInstance().saveData("ScreenWidth", ScreenWidth);
    }


    private static int screenWidthCacheCache = -1;

    public static int getScreenHeight() {
        if (screenWidthCacheCache != -1) {
            return screenWidthCacheCache;
        }
        screenWidthCacheCache = (int) MyApplicaiton.getInstance().getData("ScreenHeight", 1080);
        return screenWidthCacheCache;
    }


    public static void setScreenHeight(int ScreenHeight) {
        screenWidthCacheCache = ScreenHeight;
        MyApplicaiton.getInstance().saveData("ScreenHeight", ScreenHeight);
    }

    private static int PowerOnOffEnableCache = -1;

    public static void setPowerOnOffEnable(int powerOnOffState) {
        PowerOnOffEnableCache = powerOnOffState;
        MyApplicaiton.getInstance().saveData("powerOnOffState", powerOnOffState);
    }

    /***
     * 0 关闭
     * 1 打开
     * @return
     */
    public static boolean getPowerOnOffEnable() {
        if (PowerOnOffEnableCache != -1) {
            return PowerOnOffEnableCache == 1;
        }
        PowerOnOffEnableCache = (int) MyApplicaiton.getInstance().getData("powerOnOffState", 0);
        return PowerOnOffEnableCache == 1;
    }
}
